﻿using xu.TinyDBConfigProvider;

namespace Test.WebApi.SQLite.common;

/// <summary>
/// 配置文件帮助类
/// </summary>
public class ConfigHelper
{
    private static IConfiguration _configuration;

    static ConfigHelper()
    {
        string connStr = "Data Source=TinyDB.sqlite";
        IConfigurationBuilder builder = new ConfigurationBuilder().AddTinyDBConfiguration(() => new Microsoft.Data.Sqlite.SqliteConnection(connStr), reloadOnChange: true, reloadInterval: TimeSpan.FromSeconds(2));
        _configuration = builder.Build();
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static IConfigurationSection GetSectionValue(string key)
    {
        return _configuration.GetSection(key);
    }

    public static string GetSectionValue2(string key)
    {
        return _configuration.GetSection(key).Value;
    }
}
